<?
if(!$_SESSION['memberID']){
    header('Location:/new/d/shops/gtindex.html');
    exit;
}
include_once("/var/www/html/new/d/common/page.php");
include_once("/var/www/html/new/d/shops/call/OrderRecord.php");
include_once("/var/www/html/new/d/class/ProOrder.php");
include_once("/var/www/html/new/conf/yd.le.je");
include_once('/var/www/html/new/d/common/autoload.php');
$mem = new \pft\Member\MemberAccount($GLOBALS['le']);
$m_info = $mem->GetOne($_SESSION['memberID']);
$tt=array("dname","address","mobile","qq","headphoto","cname","ctel","alipay","position","email","com_name","com_type","province","city","fax","website","business","short_company_name");
$ydle=new yd_go_sql();
$ydle->connect(); 
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$memberID = $_SESSION['sid'];
$_REQUEST['begintime']='2014-12-07 00:00:00';
$_REQUEST['endtime']=date('Y-m-d H:i:s');
$currentPage = $_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize = $_REQUEST['pageSize']?$_REQUEST["pageSize"]:5;
// print_r($_SESSION);

$pOrder=buyProOrderObject($memberID,$s,$_SESSION['sdtype']);
$r=$pOrder->_orderlist($currentPage,$pageSize);
// print_r($r);
// 判断订单是否为主订单  true为主订单
function isMainOrder($field){
	return ($field=='main' || $field!=0 ) ? true:false;
}
// 复票订单主订单
function echoMainOrder($obj){
	return ((String)$obj->UUconcat_id=='main') ? (String)$obj->UUordernum:(String)$obj->UUconcat_id;
}
$count=$pOrder->orderlistTotal();
$uuStatus = array(
    0=>"未使用",
    1=>"<em class='green'>已使用</em>",
    2=>"已过期",
    3=>"<em class='red'>已取消</em>",
    4=>"被替代",
    5=>"<em class='green'>已使用</em><br/><em class='red'>(被修改)</em>",
    6=>"已撤销",
    7=>"部分使用"
);
// $orderxml = $s->Order_Globle_Search('',$memberID,'','','','','','','','','','','','', '', '0|1|2|3|4|5|6',  '0|1|2', '', '', 1, 0, 15, 0, 1, '', 0, '',0, '','' ,'', 0, 0);
// $r = simplexml_load_string($orderxml);
// $concat=0;
// print_r($r);
?>
<? include("ggheader.php") ?>
	<link rel="stylesheet" type="text/css" href="http://www.12301.cc/css/page.css"/>
	<link rel="stylesheet" type="text/css" href="http://www.12301.cc/shops/css/gmem.css"/>
	<div class="mem_con">
		<div class="mem_left">
			<div id="mem_photo"><a href="javascript:showBg();"  class="info_img"><img src="<?=$m_info['headphoto']?$m_info['headphoto']:"images/gggulang1.jpg"?>" title="修改头像"/></a></div>
			<ul>
				<li><a href="gmem_Data.html">个人资料</a></li>
				<li><a href="gmem_pass.html">修改密码</a></li>
				<li><a href="gmem.html">订单中心</a></li>
				<!-- <li><a href="#">安全退出</a></li> -->
			</ul>
		</div>
		<div class="mem_right">
			<div id="" class="hcon">
				<table class="proTable fixed " ><!-- id="tbl_evlt" -->
					<thead id="proTableHead">
						<tr>
							<th class="col_1">订单号</th>
							<th class="col_2">产品信息</th>
							<th class="col_3">取票人信息</th>
							<th class="col_4">订单状态</th>
							<th class="col_5">总金额</th>
							<th class="col_6">操作</th>
						</tr>
					</thead>
					<tbody>
						<!-- 第1个产品 -->
						<?
						foreach($r as $row):
							$childNum = count($row['childOrder']);
							$orderid=(string)$row['mainOrder']->UUordernum;
							$sql = "select id from uu_discuss where orderid='$orderid' limit 1";
							$ydle->query($sql);
							$ydle->fetch_assoc();
							$commentId = $ydle->f('id');
						?>
						<tr class="listHead">
							<td colspan="8">
								<div>
								<a href="" title="<?=(string)$row['mainOrder']->UUltitle?>" class="title" ><?=(string)$row['mainOrder']->UUltitle?></a>
								<p class="rt">
									<span class="span">下单时间：<?=(string)$row['mainOrder']->UUordertime?></span>
									<span class="span">有效期：<?=(string)$row['mainOrder']->UUbegintime?> 至 <?=(string)$row['mainOrder']->UUendtime?></span>
									<span class="span span3">验证时间：<?=(string)$row['mainOrder']->UUdtime!="0000-00-00 00:00:00"?(string)$row['mainOrder']->UUdtime:"未验证"?></span>
								</p>
								</div>
							</td>
						</tr>
						<tr class="listBody <?if(!$childNum)echo 'borderBottom';?>" >
							<td class="col_1 col codeNum" rowspan="<?=$childNum + 1?>">
							<?if(isMainOrder($row['mainOrder']->UUconcat_id)):?>
							<span  id="getCode"></span>
							<a href="" class="ordernb"><?=(string)$row['mainOrder']->UUordernum?></a>
							<input type="button" class="getCode" value="获取凭证号" data="<?=(string)$row['mainOrder']->UUordernum?>"/>
							<?else:?>
							<span  id="getCode"></span>
							<a  href="" class="ordernb"><?=(string)$row['mainOrder']->UUordernum?></a>
							<input type="button" class="getCode" value="获取凭证号" data="<?=(string)$row['mainOrder']->UUordernum?>"/>
							<?endif;?>
							<?if((string)$row['mainOrder']->UUremotenum){?>
							<span class="f_orderNum"><?=(string)$row['mainOrder']->UUremotenum?></span>
							<?}?>
							</td>
							<td class="col_2 col">
							【<?=(string)$row['mainOrder']->UUttitle?>】<span class="numPrice"> * <i><?=(string)$row['mainOrder']->UUtnum?></i> 张 * &yen;<i><?=(string)$row['mainOrder']->UUtprice/100?></i></span>
							</td>
							<td class="col_3 col" rowspan="<?=$childNum + 1?>">
								<p class="name2"><?=(string)$row['mainOrder']->UUordername?></p>
								<p class="tell"><?=(string)$row['mainOrder']->UUordertel?></p>
							</td>
							<td class="col_6 col" rowspan="<?=$childNum + 1?>">
							<span rowspan="<?=$row['totalOrder']?>">
								<p>
									<?=$uuStatus[(string)$row['mainOrder']->UUstatus]?>
									<?if((string)$row['mainOrder']->UUstatus==2 && (string)$row['mainOrder']->UUpaystatus==2) echo '<br/><span style="color:red;">(未支付)</span>';?>
								</p>
								<p class="green">
								<?if($row['mainOrder']->UUstatus==0){?>
								<?=OrderRecord::$paystatusT[(string)$row['mainOrder']->UUpaystatus]?>
								<?}?>
								</p>
							</td>
							<td class="col_7 col" rowspan="<?=$childNum + 1?>">

							<?if(!isMainOrder($row['mainOrder']->UUconcat_id)):?>
							合计<span class="totalPrice">&yen;<i><?=((int)$row['mainOrder']->UUtprice*(int)$row['mainOrder']->UUtnum)/100?></i></span>
							<?else:?>
							<?
								$total = 0;
								foreach($row['childOrder'] as $cr){
									// $total = $total + (string)$cr['totalPrice']/100 ;
									$total = $total + ((int)$cr->UUtprice*(int)$cr->UUtnum)/100;
								}
								$total += ((int)$row['mainOrder']->UUtprice*(int)$row['mainOrder']->UUtnum)/100;
							?>
							合计<span class="totalPrice">&yen;<i><?=$total?></i></span>
							<?endif;?>
							</td>
							<td class="col_8 col" rowspan="<?=$childNum + 1?>">
							<?
								$ordernum = (string)$row['mainOrder']->UUordernum;// 订单号
								if((string)$row['orderAlipay']){ // 支付
									echo '<a href="/new/d/shops/alipayOrder_c.html?ordernum='.$ordernum.'" target="_blank">支付</a>';
								}elseif($row['mainOrder']->UUstatus==0){// 退票
									echo '<a href="/new/d/shops/call/handle.php?from=order_cancel&ordernum='.$ordernum.'" target="_blank">退票</a>';
								}
								if((string)$row['mainOrder']->UUifpack!=2){// 不是子票的才显示取消、修改、重发
							// 取消
                            // echo "orderOperAuth($row,$memberID,$account,orderCancel)";
							if(OrderRecord::orderOperAuth($row,$memberID,$account,"orderCancel"))
								echo '<a act="cancel" class="orderHandle" href="call/handle.php?from=order_cancel&&ordernum='.$order.'">取消</a><br/>';
							// 修改
							if(OrderRecord::orderOperAuth($row,$memberID,$account,"orderAlter")){
                                $concat='';
                                if(isMainOrder($row['mainOrder']->UUconcat_id)){
                                echo '<a  class="alter" href="call/handle.php?from=orderAlterHtml&ordernum='.$order.'&concat=1">修改</a><br/>';
                                }else{
                                echo '<a  class="alter" href="call/handle.php?from=orderAlterHtml&ordernum='.$order.'">修改</a><br/>';
                                }
                            }

								
							// 重发
							if(OrderRecord::orderOperAuth($row,$memberID,$account,"orderResend"))
								echo '<a act="cancel" class="resend" href="call/handle.php?from=order_resend&&ordernum='.$order.'">重发</a><br/>';
						}
							?>
							</td>
						</tr>
						<?foreach($row['childOrder'] as $cr):?>
						<tr class="listBody borderBottom borderTop">
							<td class="col_2 col">
								【<?=(string)$cr->UUttitle?>】
								<span class="numPrice"> * <i><?=(string)$cr->UUtnum?></i> 张 * &yen;<i><?=(string)$cr->UUtprice/100?></i></span>
							</td>
						</tr>
						<?endforeach;//子票?>
							<tr class="marTop"><td colspan="8"></td></tr>
						<?endforeach;?>
					</tbody>
				</table>
				<?page($count,$currentPage,$pageSize,$order,$by);?>
			</div>
		</div>	
	</div>	
<script src="http://www.12301.cc/js/ui/PopWindow.js" type="text/javascript"></script>
<script>
/*获取凭证号*/
	$(function(){
	$(".getCode").click(function(){
       // alert($(".getCode").length);
       // alert($(".codeNum").length);
        //index = $(".getCode").index($(this));     
		//alert(index);
        var orderId= $(this).attr("data");
		$.ajax({
            "url":"call/handle.php?from=orderView&act=getCode&ordernum="+orderId,
            "dataType":"json",
            "success":function(json){
				alert(json.msg);
               // $("#getCode").html(json.msg);
                //$(".codeNum").eq(index).html(json.msg);
                //$("#getCode").css({"font-weight":"bold","color":"#FF0000"});
            }
        })
	})
});

/*修改头像*/
function uploadevent(status,picUrl,callbackdata){
    closeBg();
    status += ''; 
    switch(status){
     case '1':
		var time = new Date().getTime();
		// var filename162 = picUrl+'_162.jpg';
        // alert(filename162);
        document.getElementById('user_photo').src=""+picUrl+"";
		 window.parent.location='shops/gmem_Data.html';
        break;
    case '-1':
        window.parent.location='shops/gmem_Data.html';
        break;
    default:
		window.parent.location='shops/gmem_Data.html';
    } 
}

/*修改头像遮罩*/
function showBg() { 
	var bh = $("html").height(); 
	var bw = $("html").width(); 
	$("#fullbg").css({ 
	height:bh, 
	width:bw, 
	display:"block" 
	}); 
	$("#dialog").show(); 
} 
function closeBg() { 
    $("#fullbg,#dialog").hide(); 
} 


	var popWindow=new PopWindow();
	$(".alter").click(function(){
		$.ajax({
			"url":$(this).attr("href"),
			"success":function(data){
				popWindow.open(data);
				$("form.changetnum input.cancel").click(function(){
					popWindow.close();
				});
				$("form.changetnum").submit(function(){
					popWindow.close();
					var str=$(this).serialize();
					$.ajax({
						"url":"call/handle.php?from=order_alter&"+str,
						"dataType":"json",
						"success":function(data){
							if(data.outcome==1){
								alert(data.msg);
								window.location=window.location.href;
							}else{
								alert(data.msg);
							}
						}
					});
					return false;
				});
				
			}
		})
		return false;
	});
	$(".orderHandle").click(function(){
		if($(this).attr("act")=="cancel"){
			if(!confirm("确定要取消该订单？")) return false;
		}
		$.ajax({
			"url":$(this).attr("href"),
			"dataType":"json",
			"success":function(data){
				if(data.outcome==1){
					alert("取消成功");
					window.location=window.location.href;
					/*$(this).parent().prev().prev().html('<em class="red">已取消</em>');
					var textT=$(this).find("a").first().text();
					$(this).parent().html(textT);*/
				}else{
					alert("取消失败"+data.msg);
				}
			}
		})
		return false;
	});
	$(".resend").click(function(){
		if($(this).attr("act")=="cancel"){
			if(!confirm("确定要重发短信？")) return false;
		}
		$.ajax({
			"url":$(this).attr("href"),
			"dataType":"json",
			"success":function(data){
				if(data.outcome==1){
					alert("重发成功");
				}else{
					alert("重发失败:"+data.msg);
				}
			}
		})
		return false;
	});
</script>
<?php include("ggfoot_m.php");?>
</body>
</html>
<div id="fullbg"></div> 
<div id="dialog"> 
<p class="close"><a href="#" onclick="closeBg();">X</a>  
<div >
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
	codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
	WIDTH="650" HEIGHT="450" id="myMovieName">
	<PARAM NAME=movie VALUE="avatar.swf">
	<PARAM NAME=quality VALUE=high>
	<PARAM NAME=bgcolor VALUE=#FFFFFF>
	<param name="flashvars" value="imgUrl=./default.jpg&uploadUrl=./upfile.php&uploadSrc=false" />
	<EMBED src="avatar.swf" quality=high bgcolor=#FFFFFF WIDTH="650" HEIGHT="450" wmode="transparent" flashVars="imgUrl=./default.jpg&uploadUrl=./upfile.php&uploadSrc=false"
	NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash" allowScriptAccess="always"
	PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
	</EMBED>
</OBJECT>  

